package com.prs.crm.service.oa.impl;

import java.io.File;
import java.util.Collection;

import org.hibernate.annotations.Cascade;

import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.oa.ReferScheduleDao;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.ReferSchedule;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.ReferScheduleService;

public class ReferScheduleServiceImpl extends BaseServiceImpl<ReferSchedule,ReferScheduleDao> implements ReferScheduleService{

	@Override
	public void saveReferSchedule(ReferSchedule referSchedule, File file,
			String fileName) {
		// TODO Auto-generated method stub
		Attach attach = FileUtil.getInstance().saveFile(file, fileName, "", Constrains.UPLOAD_DIR_SCHEDULE);
		if(attach.getSrc() != null) {
			referSchedule.setAttach(attach.getSrc());
		}
		this.getDao().save(referSchedule);
	}

	@Override
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	public void auditingNotPass(Integer[] ids) {
		// TODO Auto-generated method stub
		for(int i=0;i<ids.length;i++) {
			ReferSchedule refer = this.getDao().get(ids[i]);
			refer.setState(Constrains.TASK_NOTPASS);
			refer.getSchedule().setState(Constrains.TASK_NOTPASS);
			this.getDao().save(refer);
		}
	}

	@Override
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	public void auditingPass(Integer[] ids) {
		// TODO Auto-generated method stub
		for(int i=0;i<ids.length;i++) {
			ReferSchedule refer = this.getDao().get(ids[i]);
			refer.getSchedule().setState(Constrains.TASK_PASS);
			refer.setState(Constrains.TASK_PASS);
			this.getDao().save(refer);
		}
	}

	@Override
	public Collection<ReferSchedule> getAuditSchedule(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getAuditSchedule(person);
	}

	@Override
	public Collection<ReferSchedule> getAuditScheduleByLevel(Person person,
			String level) {
		// TODO Auto-generated method stub
		return this.getDao().getAuditScheduleByLevel(person,level);
	}

}
